//http://docs.oracle.com/javase/7/docs/api/

import java.io.*;
import java.util.*;
import java.lang.Math;


public class Main{  
	static String version="v0.1 2013/09/06";//useless now
	//------------------------------------------------
	private static final int _TX_			=0;
	private static final int _RX_			=1;
	private static final int _Tag_			=2;

	private static final int _DelayFirst_		=3;	//default:	0
	private static final int _DelayLast_		=4;	//default:	0

	private static final int _RepeatOk_		=5;	//default:	0
	private static final int _JmpOkFirst_		=6;
	private static final int _JmpOkLast_		=7;

	private static final int _RepeatFail_		=8;	//default:	0
	private static final int _JmpFailFirst_	=9;
	private static final int _JmpFailLast_		=10;

	private static final int _TimeOut_		=11;	//default:	50
	private static final int _RepeatTimeOut_	=12;
	private static final int _JmpTimeOutFirst_	=13;
	private static final int _JmpTimeOutLast_	=14;

	private static final int _MaxLen_		=15;
	private static final int _Padding_		=16;	//default:	FF

	private static final int _TxModify_		=17;
	private static final int _RxModify_		=18;
	private static final int _Jmp_			=19;

	private static final int _ArraySize_		=20;	//tatol size of array ,put in the last

	private static String[] rbuf=new String[_ArraySize_];
	//------------------------------------------------
	private static final int _DBGparseString_	=0x0001;
	private static final int _DBGOther_		=0x0002;
	private static final int _DBGTx_		=0x0004;
	private static final int _DBGRx_		=0x0008;

	private static final int _DBGUARTTx_		=0x0010;
	private static final int _DBGUARTRx_		=0x0020;
	private static int dbg=0x08;
	//------------------------------------------------

	private static DBG dbgmessage=new DBG("main.dbg",0x03);
//								_ShowDeltaTime_	=0x01;
//								_ShowOnScreen_	=0x02;

	//------------------------------------------------
	private static String[] comList;
	private static ComPort comport=new ComPort(0x200);
	private static FileExe readfile=new FileExe();
	private static StringProcess sp=new StringProcess();
	private static Date date=new Date();
	//------------------------------------------------
	private static int select=0;
	private static int defaultselect=0;
	private static int baudRate=115200;
	private static int defaultBaudRate=115200;
	private static int TmpInt=0;
	private static int index=0;
	private static int oldtime=0;

	private static boolean txModifyFirst=false;	//update new modify condition
	private static boolean rxModifyFirst=false;	//update new modify condition

	private static int UARTCheck=0;	//0:success
					//1:timeout
					//2:rx wrong
	private static final int _UART_SUCCESS_=0;
	private static final int _UART_TIMEOUT_=1;
	private static final int _UART_RXWRONG_=2;
	private static int tmpindex=0;
	//------------------------------------------------
	private static String srcfile="a.txt";
	private static String seperateString="<";
	private static String[] removeString={"\t"," ","\r\n"};
	private static String[][] db;
	private static String 	TmpString	="";

	private static byte[]	Tx		={},
		Rx		={},
		TmpRx		={};

     	private static String[] allString;
	private static String oldString="";


	private static int ComEnable=1;	//0:disable
					//1:enable ComPort
					//2:speed up(not select)
			


    public static void main(String[] args) {  
sp.setDBG(0x00);


//System.out.println("int max="+Integer.MAX_VALUE);
	for(int i=0;i<args.length;i++){
//System.out.println(i+":"+args[i]);
		switch(args[i]){
			case "-s"://src file
				i++;
				if(sp.isStringValid(args[i])){
					srcfile=args[i];
				}
				break;

			case "-v":
				System.out.println("================= Version ===============");
				System.out.println("2013/08/13");
				break;
			case "-h"://help
				dbgmessage.save("================= Help ==================");
				dbgmessage.save("-s   		:source file");
				dbgmessage.save("-com 		:default com port");
				dbgmessage.save("-baud		:default baudrate");
				dbgmessage.save("-h   		:for help");
				dbgmessage.save("-v   		:for version");
				dbgmessage.save("-speedup   	:for speedup,use default comport value");
				dbgmessage.save("-dbg   	:show dbg message");
				dbgmessage.save("		0x0001:_DBGparseString_");
				dbgmessage.save("		0x0002:_DBGOther_");
				dbgmessage.save("		0x0004:_DBGTx_");
				dbgmessage.save("		0x0008:_DBGRx_");
				dbgmessage.save("		0x0010:_DBGUARTTx_");
				dbgmessage.save("		0x0020:_DBGUARTRx_");
				dbgmessage.save("");
				dbgmessage.save("cmd ex:-com 5 -baud 921600");
				dbgmessage.save("");
				dbgmessage.save("Table item list as below,delay unit=1ms");
				dbgmessage.save("TX");
				dbgmessage.save("RX");
				dbgmessage.save("Tag");
				dbgmessage.save("DelayFirst\t:default=0");
				dbgmessage.save("DelayLast\t:default=0");
				dbgmessage.save("RepeatOk\t:default=0");
				dbgmessage.save("JmpOkFirst");
				dbgmessage.save("JmpOkLast");
				dbgmessage.save("RepeatFail\t:default=0");
				dbgmessage.save("JmpFailFirst");
				dbgmessage.save("JmpFailLast");
				dbgmessage.save("TimeOut\t\t:default=50");
				dbgmessage.save("RepeatTimeOut");
				dbgmessage.save("JmpTimeOutFirst");
				dbgmessage.save("JmpTimeOutLast");
				dbgmessage.save("MaxLen");
				dbgmessage.save("Padding\t\t:default=FF");
				dbgmessage.save("_TxModify_\t:(index,min,max,add)");
				dbgmessage.save("_TxModify_\t:(index,min,max,add)");
				dbgmessage.save("Jmp");
				dbgmessage.save("");
				dbgmessage.save("table ex:<UART>Tag=0,Tx=13230101,Jmp=0");
				break;
			case "-com":
				i++;
				if(sp.isInt(args[i])){
					defaultselect=Integer.parseInt(args[i]);
				}
				break;
			case "-baud":
				i++;
				if(sp.isInt(args[i])){
					defaultBaudRate=Integer.parseInt(args[i]);
				}
				break;
			case "-speedup":
				ComEnable=2;
				break;
			case "-dbg":
				i++;
				if(sp.isInt(args[i])){
					dbg=sp.byteToInt(sp.stringToByte(args[i]),0);
				}

				break;
			default:
				System.out.println("useless parameter:"+args[i]);
				break;
		}
	}

//	System.out.println("defaultselect:"+defaultselect);
//	System.out.println("defaultBaudRate:"+defaultBaudRate);

//	System.out.println("=========================================");
	System.out.println("==== RxTx test robot=="+version+"====");

	if(ComEnable>0){
		comList=comport.getList();
		
		for(int i=0;i<comList.length;i++){
			System.out.println(i+"\t:"+comList[i]);  
		}
	}


	try{


		readTable();

		System.out.println("\n\n");  


//select com port--------------------------------------------------------------------------------------------
		if(ComEnable>0){
			BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));

			do{
				if(select>=comList.length){
					System.out.println("== error index,pls input agagin =========");
				}
				System.out.println();
				System.out.print("Select Com(default:"+defaultselect+"):");

				if(ComEnable!=2){
					String tmpstring=buf.readLine();
	
					if(tmpstring.equals("")){
						select=defaultselect;
					}
					else{
						select=Integer.parseInt(tmpstring);
					}
				}
			}
			while(select>=comList.length && ComEnable!=2);


			System.out.println();


//select baudrate--------------------------------------------------------------------------------------------
			System.out.print("Select BaudRate(default:"+defaultBaudRate+"):");

			if(ComEnable!=2){
				String tmpstring=buf.readLine();
				if(tmpstring.equals("")){
					baudRate=defaultBaudRate;
				}
				else{
					baudRate=Integer.parseInt(tmpstring);
				}
			}	
			System.out.println();
//open com port--------------------------------------------------------------------------------------------
comport.setDBG(0);

			comport.connect(comList[select],baudRate);  

		}
/*
		if(ComEnable==2)//delay for show awhile
		{
			oldtime=(int)System.currentTimeMillis();
			while((((int)System.currentTimeMillis()-oldtime)<3000));
		}
*/
		//execise db------------------------------------
		index=0;

		do{
			tmpindex++;
			//_DelayFirst_-------------------------------------
			oldtime=(int)System.currentTimeMillis();
			while(((int)System.currentTimeMillis()-oldtime)<Integer.parseInt(db[index][_DelayFirst_]));


			if(sp.isStringValid(db[index][_TxModify_]))
			{
//dbgmessage.save("rxModifyFirst"+rxModifyFirst);
				sp.byteModifyTx(Tx,db[index][_TxModify_],txModifyFirst);
				rxModifyFirst=false;
			}
			//_TX_---------------------------------------------
			if(sp.isStringValid(db[index][_TX_])){
	

if((dbg&_DBGTx_)==_DBGTx_){
	TmpString="\tdb["+index+"][_TX_]\t:"+db[index][_TX_];
	dbgmessage.save(TmpString);
}
				//_Padding_------------------------------------	
				if(sp.isStringValid(db[index][_MaxLen_])){
					if(Integer.parseInt(db[index][_MaxLen_])>(db[index][_TX_].length()/2)){
						TmpInt=Integer.parseInt(db[index][_MaxLen_])-(db[index][_TX_].length()/2);
						for(int n=0;n<TmpInt;n++){
							db[index][_TX_]+=db[index][_Padding_];
						}
					}
				}



				Tx=sp.stringToByte(db[index][_TX_]);



				Tx=sp.byteModifyTx(Tx,db[index][_TxModify_],txModifyFirst);
//				rxModifyFirst=false;

if((dbg&_DBGTx_)==_DBGTx_){	
	TmpString="\t\tTx\t:";
	TmpString+=sp.byteToString(Tx);
	dbgmessage.save(TmpString);
}
				if((dbg&_DBGUARTTx_)==_DBGUARTTx_){
					TmpString="["+index+"]\tUART Tx:";
					TmpString+=sp.byteToString(Tx);
					dbgmessage.save(TmpString,false);
				}

				UARTCheck=_UART_SUCCESS_;
				oldtime=(int)System.currentTimeMillis();
				do{

					if(		(((int)System.currentTimeMillis()-oldtime)<Integer.parseInt(db[index][_TimeOut_])) 
						||	(Integer.parseInt(db[index][_TimeOut_])==999)					){
						UARTCheck=_UART_SUCCESS_;
					}
					else{
						UARTCheck=_UART_TIMEOUT_;
					}
				}
				while(		(UARTCheck==_UART_SUCCESS_			)
					&&	((Tx=comport.setTxBuf(Tx,Tx.length))!=null	));


				//_TimeOut_-------------------------------------
				Tx=sp.stringToByte(db[index][_TX_]);
				if(UARTCheck==_UART_TIMEOUT_){
					if((dbg&_DBGUARTTx_)==_DBGUARTTx_){

						//TmpString="["+index+"]\tUART Tx:";
						//TmpString+=sp.byteToString(Tx);
						TmpString=("  (_TimeOut_:"+sp.byteToString(Tx)+")");
						dbgmessage.save(TmpString);


					}
				}
				else{

					if((dbg&_DBGUARTTx_)==_DBGUARTTx_){
						//TmpString="["+index+"]\tUART Tx:";
						//TmpString+=sp.byteToString(Tx);
						TmpString="  (_OK_)";
						dbgmessage.save(TmpString);
					}

					UARTCheck=_UART_SUCCESS_;
				}
			}
			//_RX_---------------------------------------------
			else if(db[index][_RX_].length()!=0){
if((dbg&_DBGRx_)==_DBGRx_){
	TmpString="\tdb["+index+"][_RX_]\t:"+db[index][_RX_];
	dbgmessage.save(TmpString);
}
				//_Padding_------------------------------------	
				if(sp.isStringValid(db[index][_MaxLen_])){
					if(Integer.parseInt(db[index][_MaxLen_])>(db[index][_RX_].length()/2)){
						TmpInt=Integer.parseInt(db[index][_MaxLen_])-(db[index][_RX_].length()/2);
						for(int n=0;n<TmpInt;n++){
							db[index][_RX_]+=db[index][_Padding_];
						}

					}
				}

				Rx=sp.stringToByte(db[index][_RX_]);

if((dbg&_DBGRx_)==_DBGRx_){
	TmpString="\t\tRx\t:";
	TmpString+=sp.byteToString(Rx);
	dbgmessage.save(TmpString);
}
				oldtime=(int)System.currentTimeMillis();


				UARTCheck=_UART_SUCCESS_;
				oldtime=(int)System.currentTimeMillis();
				do{
					TmpRx=comport.getRxBuf(0x00);
					//comport.reset();
					TmpString="";
					if(TmpRx.length>0){

						TmpString=sp.byteToString(TmpRx);
					}

					if(		(((int)System.currentTimeMillis()-oldtime)<Integer.parseInt(db[index][_TimeOut_]))
						||	(Integer.parseInt(db[index][_TimeOut_])==999)					){
						UARTCheck=_UART_SUCCESS_;
					}
					else{
						UARTCheck=_UART_TIMEOUT_;
					}


				}
				while(		(UARTCheck==_UART_SUCCESS_			)
					&&	(TmpString.length()<db[index][_RX_].length())
				//	&&	(TmpString.indexOf(db[index][_RX_])==-1		)
													);


				//_TimeOut_-------------------------------------
				Rx=sp.stringToByte(db[index][_RX_]);
				if(UARTCheck==_UART_TIMEOUT_){
					if((dbg&_DBGUARTRx_)==_DBGUARTRx_){
						TmpString="["+index+"]\t\tUART Rx:";
						TmpString+=sp.byteToString(Rx);
						TmpString+=("  (_TimeOut_:"+sp.byteToString(TmpRx)+")");
						dbgmessage.save(TmpString);
					}

				}
				else{
					if(TmpString.indexOf(db[index][_RX_])!=-1){
						if((dbg&_DBGUARTRx_)==_DBGUARTRx_){

							if(TmpString.equals(db[index][_RX_])){
								TmpString="["+index+"]\t\tUART Rx:";
								TmpString+=sp.byteToString(Rx);
								TmpString+="  (_OK_)";
	
							}
							else{
								TmpString="["+index+"]\t\tUART Rx:";
								TmpString+=sp.byteToString(Rx);
								TmpString+="  (_OK_:"+sp.byteToString(TmpRx)+")";
							}
							dbgmessage.save(TmpString);
						}

						UARTCheck=_UART_SUCCESS_;
						comport.reset();
					}
					else{
						if((dbg&_DBGUARTRx_)==_DBGUARTRx_){
							TmpString="["+index+"]\t\tUART Rx:";
							TmpString+=sp.byteToString(Rx);
							TmpString+=("  (_RXWrong_:"+sp.byteToString(TmpRx)+")");
							dbgmessage.save(TmpString);
						}
						UARTCheck=_UART_RXWRONG_;	
					}
				}


			}


			//check ok-------------------------------------	
			oldString="";//use for next tag use
			if(UARTCheck==_UART_SUCCESS_){
				if(sp.isStringValid(db[index][_RepeatOk_])){
					if(Integer.parseInt(db[index][_RepeatOk_])>0){
						if(Integer.parseInt(db[index][_RepeatOk_])>0){
							if(sp.isStringValid(db[index][_JmpOkFirst_])){
								oldString=db[index][_JmpOkFirst_];
							}
						}
						else{
							if(db[index][_JmpOkLast_].length()!=0){
								oldString=db[index][_JmpOkLast_];
							}
						}
						db[index][_RepeatOk_]=String.valueOf(Integer.parseInt(db[index][_RepeatOk_])-1);
					}
				}
			}
			//check fail-------------------------------------
			else{
				if(sp.isStringValid(db[index][_RepeatFail_])){
					if(Integer.parseInt(db[index][_RepeatFail_])>0){
						if(Integer.parseInt(db[index][_RepeatFail_])>0){
							if(sp.isStringValid(db[index][_JmpFailFirst_])){
								oldString=db[index][_JmpFailFirst_];
							}
						}
						else{
							if(db[index][_JmpFailLast_].length()!=0){
								oldString=db[index][_JmpFailLast_];
							}
						}
						db[index][_RepeatFail_]=String.valueOf(Integer.parseInt(db[index][_RepeatFail_])-1);
					}
				}		
			}
/*
			//force jmp-------------------------------------
			if(sp.isStringValid(db[index][_Jmp_])){
				oldString=db[index][_Jmp_];
			}

			//find next index-------------------------------------
			if(sp.isStringValid(oldString)){
				for(int m=0;m<allString.length;m++){
					if(oldString.equals(db[m][_Tag_])){
						tmpindex=m;
					}
				}
			}
*/
			//force jmp-------------------------------------
			if(sp.isStringValid(db[index][_Jmp_])){
				oldString=db[index][_Jmp_];
			}

			//find next index-------------------------------------
			if(sp.isStringValid(oldString)){
				for(int m=0;m<allString.length;m++){
					if(oldString.equals(db[m][_Tag_])){
						tmpindex=m;
					}
				}


				if(allString.length>0){
					if((index==allString.length-1) && tmpindex==0)
						readTable();
				}
			}

			//_DelayLast_-------------------------------------
			oldtime=(int)System.currentTimeMillis();
			while(((int)System.currentTimeMillis()-oldtime)<Integer.parseInt(db[index][_DelayLast_]));


			index=tmpindex;
		}
		while(index < (allString.length));

System.out.println("= Process Finish ========================");
//-----------------------------------------------------------------------------------------------------
	}
	catch(ArrayIndexOutOfBoundsException e){
		e.printStackTrace();
	}
	catch(IOException e){
		e.printStackTrace();
	}
	catch( Exception e ){
		e.printStackTrace();
	}  


    } 








	//================================================================================
	//================================================================================
	public static void readTable(){
		boolean error=false;
//read file ,seperate string--------------------------------------------------------------------------------------------
//sp.setDBG(0x01);
		allString=sp.parseString(readfile.readString(srcfile),seperateString,removeString);


//TX RX test--------------------------------------------------------------------------------------------
	//prcess string--------------------------------------------------------------------------------------------

		//record db-------------------------------------
		db=new String[allString.length][_ArraySize_];

System.out.println("== Test Item Number: "+allString.length);

		for(int k=0;k<allString.length;k++){

			allString[k]=allString[k].toUpperCase();
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString=k+"\t:"+allString[k];
	dbgmessage.save(TmpString);
}

		//_TX_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"Tx=".toUpperCase(),",");

			db[k][_TX_]="";

			if(sp.isStringValid(TmpString)){
				db[k][_TX_]=TmpString;
			}

if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_TX_]\t\t="+db[k][_TX_];
	dbgmessage.save(TmpString);
}

		//_RX_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"Rx=".toUpperCase(),",");
			db[k][_RX_]="";

			if(sp.isStringValid(TmpString)){
				db[k][_RX_]=TmpString;
			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_RX_]\t\t="+db[k][_RX_];
	dbgmessage.save(TmpString);
}
		//_Tag_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"Tag=".toUpperCase(),",");

			db[k][_Tag_]="";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_Tag_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_Tag_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}


//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_Tag_]=TmpString;
//				}
//			}

if((dbg&_DBGparseString_)==_DBGparseString_){
//dbgmessage.save("/"+TmpString+"/");
	TmpString="\t\tdb["+k+"][_Tag_]\t\t="+db[k][_Tag_];
	dbgmessage.save(TmpString);
}
		//_DelayFirst_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"DelayFirst=".toUpperCase(),",");
			db[k][_DelayFirst_]="0";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_DelayFirst_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_DelayFirst_]=\""+TmpString+"\" ----->this valus should be int")	;
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_DelayFirst_]=TmpString;
//				}
//			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_DelayFirst_]\t="+db[k][_DelayFirst_];
	dbgmessage.save(TmpString);
}
		//_DelayLast_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"DelayLast=".toUpperCase(),",");
	
			db[k][_DelayLast_]="0";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_DelayLast_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_DelayLast_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_DelayLast_]=TmpString;
//				}
//			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_DelayLast_]\t="+db[k][_DelayLast_];
	dbgmessage.save(TmpString);
}
		//_RepeatOk_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"RepeatOk=".toUpperCase(),",");

			db[k][_RepeatOk_]="0";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_RepeatOk_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_RepeatOk_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_RepeatOk_]=TmpString;
//				}
//			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_RepeatOk_]\t="+db[k][_RepeatOk_];
	dbgmessage.save(TmpString);
}

		//_JmpOkFirst_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"JmpOkFirst=".toUpperCase(),",");

			db[k][_JmpOkFirst_]="";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_JmpOkFirst_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_JmpOkFirst_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_JmpOkFirst_]=TmpString;
//				}
//			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_JmpOkFirst_]\t="+db[k][_JmpOkFirst_];
	dbgmessage.save(TmpString);
}
		//_JmpOkLast_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"JmpOkLast=".toUpperCase(),",");

			db[k][_JmpOkLast_]="";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_JmpOkLast_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_JmpOkLast_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_JmpOkLast_]=TmpString;
//				}
//			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_JmpOkLast_]\t="+db[k][_JmpOkLast_];
	dbgmessage.save(TmpString);
}

		//_RepeatFail_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"RepeatFail=".toUpperCase(),",");

			db[k][_RepeatFail_]="0";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_RepeatFail_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_RepeatFail_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_RepeatFail_]=TmpString;
//				}
//			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_RepeatFail_]\t="+db[k][_RepeatFail_];
	dbgmessage.save(TmpString);
}

		//_JmpFailFirst_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"JmpFailFirst=".toUpperCase(),",");

			db[k][_JmpFailFirst_]="";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_JmpFailFirst_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_JmpFailFirst_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_JmpFailFirst_]=TmpString;
//				}
//			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_JmpFailFirst_]\t="+db[k][_JmpFailFirst_];
	dbgmessage.save(TmpString);
}
		//_JmpFailLast_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"JmpFailLast=".toUpperCase(),",");

			db[k][_JmpFailLast_]="";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_JmpFailLast_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_JmpFailLast_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}	
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_JmpFailLast_]=TmpString;
//				}
//			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_JmpFailLast_]\t="+db[k][_JmpFailLast_];
	dbgmessage.save(TmpString);
}
		//_TimeOut_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"TimeOut=".toUpperCase(),",");

			db[k][_TimeOut_]="50";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_TimeOut_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_TimeOut_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_TimeOut_]=TmpString;
//				}
//			}

if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_TimeOut_]\t="+db[k][_TimeOut_];
	dbgmessage.save(TmpString);
}


		//_RepeatTimeOut_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"RepeatTimeOut=".toUpperCase(),",");

			db[k][_RepeatTimeOut_]="0";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_RepeatTimeOut_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_RepeatTimeOut_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_RepeatTimeOut_]=TmpString;
//				}
//			}

if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_RepeatTimeOut_]\t="+db[k][_RepeatTimeOut_];
	dbgmessage.save(TmpString);
}

		//_JmpTimeOutFirst_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"JmpTimeOutFirst=".toUpperCase(),",");

			db[k][_JmpTimeOutFirst_]="";


			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_JmpTimeOutFirst_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_JmpTimeOutFirst_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_JmpTimeOutFirst_]=TmpString;
//				}
//			}

if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_JmpTimeOutFirst_]="+db[k][_JmpTimeOutFirst_];
	dbgmessage.save(TmpString);
}


		//_JmpTimeOutLast_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"JmpTimeOutLast=".toUpperCase(),",");

			db[k][_JmpTimeOutLast_]="";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_JmpTimeOutLast_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_JmpTimeOutLast_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_JmpTimeOutLast_]=TmpString;
//				}
//			}

if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_JmpTimeOutLast_]\t="+db[k][_JmpTimeOutLast_];
	dbgmessage.save(TmpString);
}

		//_MaxLen_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"MaxLen=".toUpperCase(),",");

			db[k][_MaxLen_]="";

			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_MaxLen_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_MaxLen_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}	
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_MaxLen_]=TmpString;
//				}
//			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_MaxLen_]\t\t="+db[k][_MaxLen_];
	dbgmessage.save(TmpString);
}
		//_Padding_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"Padding=".toUpperCase(),",");

			db[k][_Padding_]="FF";


			if(sp.isStringValid(TmpString)){
				db[k][_Padding_]=TmpString;
			}

if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_Padding_]\t="+db[k][_Padding_];
	dbgmessage.save(TmpString);
}

		//_Jmp_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"Jmp=".toUpperCase(),",");
			db[k][_Jmp_]="";


			if(sp.isStringValid(TmpString)){
				if(sp.isInt(TmpString)){
					db[k][_Jmp_]=TmpString;
				}
				else{
					System.out.println("db["+k+"][_Jmp_]=\""+TmpString+"\" ----->this valus should be int");
					error=true;
				}
			}

//			if(TmpString!=null && TmpString!=""){
//				if(TmpString.length()>0){
//					db[k][_Jmp_]=TmpString;
//				}
//			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_Jmp_]\t\t="+db[k][_Jmp_];
	dbgmessage.save(TmpString);
}


		//_TxModify_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"TxModify=".toUpperCase(),",");
			db[k][_TxModify_]="";

			if(sp.isStringValid(TmpString)){
				db[k][_TxModify_]=TmpString;
				txModifyFirst=true;
			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_TxModify_]\t="+db[k][_TxModify_];
	dbgmessage.save(TmpString);
}


		//_RxModify_----------------------------------------------------------------------------
			TmpString=sp.getPartOfString(allString[k],"RxModify=".toUpperCase(),",");
			db[k][_RxModify_]="";

			if(sp.isStringValid(TmpString)){
				db[k][_RxModify_]=TmpString;
				rxModifyFirst=true;
			}
if((dbg&_DBGparseString_)==_DBGparseString_){
	TmpString="\t\tdb["+k+"][_RxModify_]\t="+db[k][_RxModify_];
	dbgmessage.save(TmpString);
}


			if(error){
				while(true);
			}
		}
	}



 

}  